using AndroidCaller;
using System;
using UnityEngine;
using UnityEngine.UI;

public class Gift : MonoBehaviour
{
	public CoinsController CoinsController;

	public MenuNavigation MenuNavigation;

	public GameObject gift_dialog;

	public GameObject awarded_panel;

	public Sprite icon_video;

	public Sprite icon_download;

	public Sprite icon_follow;

	public Sprite icon_heart;

	public Image item1_icon;

	public Text item1_title;

	public Text item1_description;

	public Text item1_button;

	public Image item2_icon;

	public Text item2_title;

	public Text item2_description;

	public Text item2_button;

	public string icon1 = string.Empty;

	public string title1 = string.Empty;

	public string description1 = string.Empty;

	public int coins1;

	public string button1 = string.Empty;

	public string url1 = string.Empty;

	public string icon2 = string.Empty;

	public string title2 = string.Empty;

	public string description2 = string.Empty;

	public int coins2;

	public string button2 = string.Empty;

	public string url2 = "unityads";

	private int coins;

    private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.Escape) && MenuNavigation.gift_dialog_showing)
		{
			if (awarded_panel.activeInHierarchy)
			{
				awarded_panel.SetActive(value: false);
			}
			else if (gift_dialog.activeInHierarchy)
			{
				HideAllDialogs();
			}
		}
	}

	public void HideAllDialogs()
	{
		awarded_panel.SetActive(value: false);
		gift_dialog.SetActive(value: false);
		MenuNavigation.gift_dialog_showing = false;
	}

	public void HideAwardedDialog()
	{
		awarded_panel.SetActive(value: false);
	}

	public void ShowGiftsDialog()
	{
		MenuNavigation.gift_dialog_showing = true;
		gift_dialog.SetActive(value: true);
		awarded_panel.SetActive(value: false);
	}

	public void ShowAwardedDialog()
	{
		awarded_panel.SetActive(value: true);
	}

	public void SetData(string data)
	{
		string[] array = data.Split(new string[1]
		{
			"<->"
		}, StringSplitOptions.None);
		icon1 = array[0];
		title1 = array[1];
		description1 = array[2];
		try
		{
			int.TryParse(array[3], out coins1);
		}
		catch
		{
		}
		button1 = array[4];
		url1 = array[5];
		icon2 = array[6];
		title2 = array[7];
		description2 = array[8];
		try
		{
			int.TryParse(array[9], out coins2);
		}
		catch
		{
		}
		button2 = array[10];
		url2 = array[11];
		if (icon1 == "download")
		{
			item1_icon.sprite = icon_download;
		}
		else if (icon1 == "follow")
		{
			item1_icon.sprite = icon_follow;
		}
		else if (icon1 == "heart")
		{
			item1_icon.sprite = icon_heart;
		}
		else
		{
			item1_icon.sprite = icon_video;
		}
		item1_title.text = title1;
		item1_description.text = description1;
		item1_button.text = button1;
		if (icon2 == "download")
		{
			item2_icon.sprite = icon_download;
		}
		else if (icon2 == "follow")
		{
			item2_icon.sprite = icon_follow;
		}
		else if (icon2 == "heart")
		{
			item2_icon.sprite = icon_heart;
		}
		else
		{
			item2_icon.sprite = icon_video;
		}
		item2_title.text = title2;
		item2_description.text = description2;
		item2_button.text = button2;
	}

	public void Item1Click()
	{
        //if (url1 != "unityads")
        //{
        //	CoinsController.AddCoins(coins1);
        //	ShowAwardedDialog();
        //}
        //else
        //{
        //	coins = coins1;
        //}
        AdManager.Instance.ShowVideo(() =>
        {
			VideoRewarded();
        });
    }

	public void Item2Click()
	{
        //NativeCall.Call("item2click");
        //      Debug.Log("2");
        //      if (url2 != "unityads")
        //{
        //	CoinsController.AddCoins(coins2);
        //	ShowAwardedDialog();
        //}
        //else
        //{
        //	coins = coins2;
        //}
        AdManager.Instance.ShowVideo(() =>
        {
            VideoRewarded();
        });
    }

	public void VideoRewarded()
	{
		CoinsController.AddCoins(500);
		//ShowAwardedDialog();
	}
}
